package com.sisgh.jefdv1.core.entity.field;

import com.sisgh.jefdv1.core.jdbc.table.Column;
import com.sisgh.jefdv1.util.CollectionUtils;
import com.sisgh.jefdv1.util.StringUtils;
import com.sisgh.jefdv1.util.TypeUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * 类字段工具类
 */
public class Fields {

    public static List<Field> convertToFields(List<Column> columns) {
        List<Field> fields = new ArrayList<>();

        if (CollectionUtils.isEmpty(columns)) {
            return fields;
        }

        for (Column column : columns) {
            if (column == null) {
                continue;
            }
            Field field = new Field();
            String name = column.getName();

            field.setName(StringUtils.UnderlineToCamel(name));
            field.setType(column.getType());

            field.setType(TypeUtils.JdbcToJava(column.getType()));

            fields.add(field);
        }

        return fields;
    };
}
